package com.qf.service.impl;

import com.qf.dao.DishesMapper;
import com.qf.dao.DishesRepository;
import com.qf.pojo.resp.BaseResp;
import com.qf.pojo.vo.Dishes;
import com.qf.service.DishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DishesServiceImpl implements DishesService {

    @Autowired
    DishesRepository dishesRepository;

    @Autowired
    DishesMapper dishesMapper;

    @Override
    public BaseResp findAll() {
        BaseResp baseResp = new BaseResp();
        List<Dishes> dishesList = dishesRepository.findAll();
        baseResp.setCode(200);
        baseResp.setMessage("查询成功");
        baseResp.setData(dishesList);
        return baseResp;
    }

    @Override
    public BaseResp searchLike(String dName) {
        BaseResp baseResp = new BaseResp();
        List<Dishes> dishesList = dishesMapper.searchLike(dName);
        if(dName.isEmpty()){
            baseResp.setCode(200);
            baseResp.setMessage("请输入要查询的商品");
            return baseResp;
        }
        if(dishesList.isEmpty()){
            baseResp.setCode(200);
            baseResp.setMessage("没有你查询的商品");
            return baseResp;
        }
        baseResp.setCode(200);
        baseResp.setMessage("查询成功");
        baseResp.setData(dishesList);
        return baseResp;
    }

    @Override
    public BaseResp findByDtype(String dType) {
        BaseResp baseResp = new BaseResp();
        List<Dishes> dishesList = dishesMapper.findByDtype(dType);
        baseResp.setCode(200);
        baseResp.setMessage("查询成功");
        baseResp.setData(dishesList);
        return baseResp;
    }

    @Override
    public BaseResp findByBid(Integer bid) {
        BaseResp baseResp = new BaseResp();
        List<Dishes> dishesList = dishesMapper.findByBid(bid);
        baseResp.setCode(200);
        baseResp.setMessage("ok");
        baseResp.setData(dishesList);
        return baseResp;
    }

    @Override
    public BaseResp findByTypeAndBid(String type, Integer bid) {
        BaseResp baseResp = new BaseResp();
        List<Dishes> dishesList = dishesMapper.findByTypeAndBid(type,bid);
        baseResp.setCode(200);
        baseResp.setMessage("ok");
        baseResp.setData(dishesList);
        return baseResp;
    }
}
